S2S_REPORT_CONFIG_V2 = {
    'real_time_report': True,
    'dynamic_argument': True,
    'group_by': '_s2s_appid.keyword',
    'target_event_id': ['recharge', 'withdraw', 'active', 'register', 'bind', 'app_download'],
    'values': [
        {
            "value_id": "click_distinct_count",
            "target_value": "_ip.keyword",
            "value_name": "链接点击数",
            "filter": [
                {'terms': {'_event_id': ['app_download']}}
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "new_device",
            "target_value": "_aid.keyword",
            "value_name": "新增设备",
            "filter": [
                {'terms': {'_event_id': ['register']}},
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "new_register_device",
            "target_value": "_aid.keyword",
            "value_name": "新增注册设备",
            "filter": [
                {'terms': {'_event_id': ['bind']}},
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "new_user",
            "target_value": "_user_id",
            "value_name": "新增用户",
            "filter": [
                {'terms': {'_event_id': ['register']}},
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "new_register_user",
            "target_value": "_user_id",
            "value_name": "新增注册用户",
            "filter": [
                {'terms': {'_event_id': ['bind']}},
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "total_register_user",
            "target_value": "_user_id",
            "value_name": "总绑定账号",
            "filter": [
                {'term': {'_event_id': 'bind'}}
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "active_device",
            "target_value": "_aid.keyword",
            "value_name": "活跃设备",
            "filter": [
                {'terms': {'_event_id': ['active']}},
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "active_user",
            "target_value": "_user_id",
            "value_name": "活跃用户",
            "filter": [
                {'terms': {'_event_id': ['active']}},
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "register_rate",
            "value_name": "当天注册率",
            "value_expr": "new_register_user/new_user",
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "recharge_user",
            "target_value": "_user_id",
            "value_name": "充值账号",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
            ],
            "operation": "cardinality",
        },

        {
            "value_id": "recharge_device",
            "target_value": "_aid.keyword",
            "value_name": "付费设备",
            "filter": [
                {"term": {"_event_id": "recharge"}}
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "recharge_amount",
            "target_value": "recharge_price",
            "value_name": "充值金额",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
            ],
            "value_type": "float"
        },
        {
            "value_id": "arpu",
            "value_name": "Arpu",
            "value_expr": "recharge_amount/new_user"
        },
        {
            "value_id": "arppu",
            "value_name": "Arppu",
            "value_expr": "recharge_amount/recharge_user"
        },

        {
            "value_id": "recharge_rate",
            "value_name": "付费率",
            "value_expr": "recharge_user/active_user",
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "withdraw_amount",
            "target_value": "withdraw_real_price",
            "value_name": "提现金额",
            "filter": [
                {'term': {'_event_id': 'withdraw'}},
            ],
        },
        {
            "value_id": "profit_amount",
            "target_value": ["recharge_price", "-", "withdraw_real_price"],
            "value_name": "营收",
            "filter": [
                {'terms': {'_event_id': ['recharge', 'withdraw']}},
            ],
        },
        {
            "value_id": "profit_rate",
            "value_name": "营收率",
            "value_expr": "profit_amount/recharge_amount",
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "new_recharge_amount",
            "target_value": "recharge_price",
            "value_name": "新增充值金额",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'_is_new_user': 1}}
            ],
            "value_type": "float"
        },
        {
            "value_id": "new_recharge_user",
            "target_value": "_user_id",
            "value_name": "新增充值账号",
            "filter": [
                {'term': {'_event_id': 'recharge'}},
                {'term': {'_is_new_user': 1}}
            ],
            "operation": "cardinality",
        },
        {
            "value_id": "new_recharge_device",
            "target_value": "_aid.keyword",
            "value_name": "新付费设备",
            "filter": [
                {'term': {"_event_id": "recharge"}},
                {"term": {"_is_new_user": 1}}
            ],
            "operation": "cardinality"
        },
        {
            "value_id": "new_register_recharge_ratio",
            "value_name": "新注充率",
            "value_expr": "new_recharge_user/new_user",
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "new_user_arpu",
            "value_name": "新用户Arpu",
            "value_expr": "new_recharge_amount/new_user"
        },
        {
            "value_id": "new_user_arppu",
            "value_name": "新用户Arppu",
            "value_expr": "new_recharge_amount/new_recharge_user"
        },
        {
            "value_id": "new_recharge_rate",
            "value_name": "新用户付费率",
            "value_expr": "new_recharge_user/new_register_user",
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "first_recharge_user",
            "target_value": "_user_id",
            "value_name": "首充账号",
            "filter": [
                {"term": {"_event_id": "recharge"}},
                {"terms": {"_user_id": "${first_recharge_user_pool}"}}
            ],
            "operation": "cardinality"
        },
        {
            "value_id": "first_recharge_count",
            "target_value": "recharge_price",
            "value_name": "首充金额",
            "filter": [
                {"term": {"_event_id": "recharge"}},
                {"terms": {"_user_id": "${first_recharge_user_pool}"}}
            ],
            "value_type": "float"
        },
        {
            "value_id": "device_stay_2",
            "target_value": "_aid.keyword",
            "value_name": "设备次留数",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_active_days": 1}}
            ],
            "time_range": {
                "_event_time": [1, 1]
            },
            "operation": "cardinality",
        },
        {
            "value_id": "device_stay_2_ratio",
            "value_name": "次日设备留存率",
            "value_expr": "device_stay_2/new_device",
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "user_stay_2",
            "target_value": "_user_id",
            "value_name": "用户次留数",
            "filter": [
                {"term": {"_event_id": "active"}},
                {"term": {"_active_days": 1}}
            ],
            "time_range": {
                "_event_time": [1, 1]
            },
            "operation": "cardinality",
        },
        {
            "value_id": "user_stay_2_ratio",
            "value_name": "次日用户留存率",
            "value_expr": "user_stay_2/new_user",
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
        {
            "value_id": "new_bind_recharge_ratio",
            "value_name": "新绑充率",
            "value_expr": "new_recharge_user/new_register_user",
            "fmt": lambda v: float("%.2f" % (v * 100))
        },
    ]
}


